package com.sihan.swvp.service.sys;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.sihan.swvp.dao.sys.VideoAutoMatchDao;
import com.sihan.swvp.entity.video.VideoSyn;

/**
 * 视频任务匹配服务
 * @author jch
 *
 */
@Component
public class VideoAutoMatchService {
	@Autowired
	VideoAutoMatchDao matchDao;
	
	/**
	 * 获取没有匹配的任务
	 * @param params 参数
	 * @return
	 */
	public List<VideoSyn> getNoMatchsVideo(Map<String,Object> params){
		
		List<VideoSyn> videos = matchDao.getNoMatchsVideo(params);
		
		return videos;
	}

	/**
	 * 添加任务视频
	 * @param video 视频
	 */
	public void addTaskVideo(VideoSyn video){
		matchDao.deleteTaskVideo(video);
		matchDao.addTaskVideo(video);
		changeMatchState(video,true);
		matchDao.taskComplete(video.getTask_id());
	}
	
	public void updateTaskVideo(String vmid,String gcid) {
		// TODO Auto-generated method stub
		matchDao.updateTaskVideo(vmid, gcid);
	}
	
	/**
	 * 修改匹配状态
	 * @param video 视频
	 * @param match 匹配状态 true已匹配、false未匹配
	 */
	public void changeMatchState(VideoSyn video,boolean match){
		matchDao.changeMatchState(video.getId(),match ? 1 : 0);
	}
	
	/**
	 * 通过角色获取任务
	 * @param roleid 角色ID
	 * @param start 开始时间
	 * @param end 结束时间
	 * @return
	 */
	public List<Map<String,Object>> getTaskByRole(int roleid,Date start,Date end){
		
		List<Map<String,Object>> list = matchDao.getTaskByRole(roleid,start,end);
		return list;
	}
	
	public List<Map<String,Object>> getTaskBySb(String sbid,Date start,Date end){
		
		List<Map<String,Object>> list = matchDao.getTaskBySb(sbid,start,end);
		return list;
	}
	
	public List<Map<String, Object>> getJsVideos(String taskid, String jsid){
		List<Map<String, Object>> list = matchDao.getJsVideos(taskid,jsid);
		
		return list;
	}
	
	/**
	 * 过期
	 * @param jsid
	 * @return
	 */
	public List<Map<String, Object>> getGcByJs(String jsid){
		List<Map<String,Object>> list = matchDao.getGcByJs(jsid);
		
		return list;
	}

	public List<Map<String, Object>> getGcByRw(String rwid) {
		List<Map<String,Object>> list = matchDao.getGcByRw(rwid);
		
		return list;
	}

	
}
